package shop.controls;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;

import shop.pojo.Brand;
import shop.services.BrandServices;

/**
 * Servlet implementation class BrandSel
 */
public class BrandSel extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BrandSel() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String strPage = request.getParameter("currPage");
		int page =0;
		if(strPage != null){
			page = Integer.parseInt(strPage);
		}
		List<Brand> list = new BrandServices().selPageBrand(page*6);
		HttpSession hs = request.getSession();
		hs.setAttribute("list", list);//获取当前页的品牌信息
		List<Brand> list1 = new BrandServices().selAllBrand();
		int size = list1.size();//总记录数
		int totalPage = size%6==0?size/6:size/6+1;//总页数
		hs.setAttribute("size", size);//总记录数
		hs.setAttribute("page", page);//当前页
		hs.setAttribute("totalPage", totalPage-1);
		request.getRequestDispatcher("jsp2/brandList.jsp").forward(request, response);
	}

}
